﻿#include "stdafx.h"
#include "Druid_Balance.h"
#include "PressKeyUtil.h"
#include "DefInfo/GameInfo.h"
#include "DefInfo/Team_Raid_Info.h"

Druid_Balance::Druid_Balance()
{
	action.PushSequence("HealSelf", Regrowth, [](SpellID id) {
		if (GameInfo::inst().TargetIsEnemy())
		{
			if (GameInfo::inst().GetPlayer().LostHpPecent() > 0.2f)
			{
				if (GameInfo::inst().GetPlayer().buff(Regrowth).Down())
				{
					return true;
				}
				else if (GameInfo::inst().GetPlayer().LostHpPecent() > 0.8f)
				{
					return true;
				}
			}
		}
		return false;
		});
	action.PushSequence("C0", Moonkin_Form, [](SpellID id) {
		if (GameInfo::inst().PlayerInBattle() && GameInfo::inst().GetFormID() != kf_Moonkin_Form && GameInfo::inst().shiftform().GetWaitFormID() != kf_Moonkin_Form)
		{
			if (GameInfo::inst().GetFormID() == 0 || (GameInfo::inst().GetFormID() != kf_Travel_Form && GameInfo::inst().GetFormID() != kf_Swift_Flight_Form && GameInfo::inst().GetFormID() != kf_Flight_Form))
			{
				GameInfo::inst().shiftform().AddWait(kf_Moonkin_Form);
				return true;
			}
		}
		return false;
		});

	action.PushSequence("C1", Memory_of_Lucid_Dreams, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().GetRoutineConfig().general_config.use_azerite_neck_spell != 1)
		{
			return false;
		}
		return GameInfo::inst().GetPlayerMana() <= 80;
		});
	action.PushSequence("C2", Concentrated_Flame, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().GetRoutineConfig().general_config.use_azerite_neck_spell != 1)
		{
			return false;
		}
		return GameInfo::inst().GetPlayerMana() <= 80;
		});
	action.PushSequence("C3", Reaping_Flames, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().GetRoutineConfig().general_config.use_azerite_neck_spell != 1)
		{
			return false;
		}
		return (GameInfo::inst().GetTargetHp()*1.0f) / GameInfo::inst().GetTargetHpMax() <= 0.2;
		});
	//////////////////////////////////////////////////////////////////////////
	// ConRo
	action.PushSequence("CZ", Reaping_Flames, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().GetRoutineConfig().general_config.use_conro_spell != 1)
		{
			return false;
		}
		return true;
		});
	
	//////////////////////////////////////////////////////////////////////////

	action.PushSequence("D", Celestial_Alignment, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		return GameInfo::inst().GetPlayerMana() >= 40;
		});

	action.PushSequence("E", Starfall, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().buff().Get(Starlord).stack < 3 || GameInfo::inst().buff().Get(Starlord).remains >= 8)
		{
			if (GameInfo::inst().SpellTarget().Get(Starfall) >= GameInfo::inst().Variable().starfall_targets)
			{
				return true;
			}
		}
		return false;
		});

	action.PushSequence("F", Starsurge, [](SpellID id) {
		// 		if ((GameInfo::inst().talent().Get(kStarlord).enbale
		// 			&& (GameInfo::inst().buff.Get(Starlord).stack < 3
		// 				|| GameInfo::inst().buff().Get(Starlord).remains >= 8
		// 				&& GameInfo::inst().buff().Get(Arcanic_Pulsar).stack < 8)
		// 			|| !GameInfo::inst().talent().Get(kStarlord).enbale
		// 			&& (GameInfo::inst().buff().Get(Arcanic_Pulsar).stack < 8 || GameInfo::inst().buff().Get(Celestial_Alignment).Up()))
		// 			&& GameInfo::inst().SpellTarget() < GameInfo::inst().Variable().sf_targets
		// 			&& (GameInfo::inst().buff().Get(Lunar_Empowerment).stack + GameInfo::inst().buff().Get(Solar_Empowerment).stack) < 4
		// 			&& GameInfo::inst().buff().Get(Solar_Empowerment).stack < 3
		// 			&& GameInfo::inst().buff().Get(Lunar_Empowerment).stack < 3
		// 			&& (!GameInfo::inst().Variable().sf_targets || !GameInfo::inst().buff().Get(Celestial_Alignment).Up() || !GameInfo::inst().prev().Get(Starsurge)) || !GameInfo::inst().SpellCostManaCheck(Solar_Wrath))
		// 		{
		// 			return true;
		// 		}
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		do
		{
			if (!GameInfo::inst().Ap_Check(Solar_Wrath_Balance) || GameInfo::inst().GetPlayerMana() >= 85)
			{
				return true;
			}
			// 如果启用 星辰领主 天赋
			if (GameInfo::inst().talent().Get(kStarlord).enbale)
			{
				// 星辰领主buff 小于3层 或 剩余时间大于8秒
				if (GameInfo::inst().buff().Get(Starlord).stack < 3 || GameInfo::inst().buff().Get(Starlord).remains >= 8)
				{
					break;
				}
			}
			else if (GameInfo::inst().buff().Get(Celestial_Alignment).Up() || true)
			{
				// 如果有超凡之盟的buff
				break;
			}
			return false;
		} while (0);
		do
		{
			// 如果施法目标小于4人
			if (GameInfo::inst().SpellTarget().Get(Starfall) < GameInfo::inst().Variable().starfall_targets)
			{
				// 日光增效 + 月光增效Buff 小于4层
				if ((GameInfo::inst().buff().Get(Lunar_Empowerment).stack + GameInfo::inst().buff().Get(Solar_Empowerment).stack) < 4)
				{
					// 日光增效 小于3层
					if (GameInfo::inst().buff().Get(Solar_Empowerment).stack < 3)
					{
						// 月光增效 小于3层
						if (GameInfo::inst().buff().Get(Lunar_Empowerment).stack < 3)
						{
							break;
						}
					}
				}
			}
			return false;
		} while (0);
		do
		{
			if (!GameInfo::inst().TargetIsEnemy())
			{
				return false;
			}
			// 没有超凡之盟 ， 或者 之前没用 星涌术
			if (((!GameInfo::inst().buff().Get(Celestial_Alignment).Up() || !GameInfo::inst().prev().Get(Starsurge))))
			{
				return true;
			}
		} while (0);
		return false;
		});
	action.PushSequence("G", Sunfire, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (!GameInfo::inst().Ap_Check(Sunfire))
		{
			return false;
		}
		if (GameInfo::inst().GetTarget().debuff(Moonfire_buff).Up() || GameInfo::inst().SpellTarget().Get(Sunfire) > 1 + GameInfo::inst().talent().Get(kTwin_Moons).enbale)
		{
			if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up() || !GameInfo::inst().prev().Get(Sunfire))
			{
				if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up() || GameInfo::inst().buff().Get(Celestial_Alignment).remains > GameInfo::inst().GetTarget().debuff(Sunfire_buff).duration)
				{
					if (GameInfo::inst().SpellTarget().Get(Sunfire) >= 4 || !GameInfo::inst().GetTarget().debuff(Sunfire_buff).Up())
					{
						return true;
					}
				}
			}
		}
		return false;
		});
	action.PushSequence("H", Moonfire, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (!GameInfo::inst().Ap_Check(Moonfire))
		{
			return false;
		}
		if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up() || !GameInfo::inst().prev().Get(Moonfire))
		{
			if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up() || GameInfo::inst().buff().Get(Celestial_Alignment).remains > GameInfo::inst().GetTarget().debuff(Moonfire_buff).duration)
			{
				if (GameInfo::inst().SpellTarget().Get(Moonfire) >= 6 || !GameInfo::inst().GetTarget().debuff(Moonfire_buff).Up())
				{
					return true;
				}
			}
		}
		return false;
		});
	action.PushSequence("I", Lunar_Strike, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (GameInfo::inst().buff().Get(Solar_Empowerment).stack < 3)
		{
			if (GameInfo::inst().Ap_Check(Lunar_Strike) || GameInfo::inst().buff().Get(Lunar_Empowerment).stack == 3)
			{
				if (GameInfo::inst().buff().Get(Warrior_of_Elune).Up()
					|| GameInfo::inst().buff().Get(Lunar_Empowerment).Up()
					|| GameInfo::inst().SpellTarget().Get(Lunar_Strike) >= 2
					&& !GameInfo::inst().buff().Get(Solar_Empowerment).Up())
				{
					if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up())
					{
						return true;
					}
				}
			}
		}
		return false;
		});
	action.PushSequence("J", Solar_Wrath_Balance, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		if (!GameInfo::inst().buff().Get(Celestial_Alignment).Up()
			|| !GameInfo::inst().prev().Get(Solar_Wrath_Balance))
		{
			return true;
		}
		return false;
		});
	action.PushSequence("Z", Sunfire, [](SpellID id) {
		if (!GameInfo::inst().TargetIsEnemy() || GameInfo::inst().GetTargetHp() == 0)
		{
			return false;
		}
		return true;
		});

	action.PushHealSequence("HealSelf", Regrowth, [](SpellID id) {
		if (GameInfo::inst().GetPlayer().LostHpPecent() > 0.05f)
		{
			if (GameInfo::inst().GetPlayer().buff(Regrowth).Down())
			{
				return true;
			}
			else if (GameInfo::inst().GetPlayer().LostHpPecent() > 0.3f)
			{
				return true;
			}
		}
		return false;
		});
	///
	auto& last = action.GetActionOrderByOrder("CZ");
	action.SetConRoSpellPoint((unsigned int *)&last.spell);
}


Druid_Balance::~Druid_Balance()
{
}

void Druid_Balance::ChooseBattleAction()
{
	if (PressKeyUtil::inst().press_battle_enbale)
	{
		do
		{
			if (!GameInfo::inst().GetPlayer().IsDeadOrGhost())
			{
				if (GameInfo::inst().PlayerInBattle() || GameInfo::inst().GetRoutineConfig().general_config.force_attack_target)
				{
					if (GameInfo::inst().TargetIsEnemy())
					{
						if (GameInfo::inst().IsPlayer_Channel_or_Casting())
						{
							return;
						}

						PressKeyUtil::inst().StartLock();
						action.DoAction();
						PressKeyUtil::inst().EndLock();
					}

				}
				else if (GameInfo::inst().GetTarget().player_hp == 0 && GameInfo::inst().GetTarget().player_hp_max == 0 || GameInfo::inst().TargetIsEnemy())
				{
					if (GameInfo::inst().IsPlayer_Channel_or_Casting())
					{
						return;
					}
					PressKeyUtil::inst().StartLock();
					action.DoHealSelfAction();
					PressKeyUtil::inst().EndLock();
				}
			}
		} while (false);
	}
}
